/*
 * Term.java
 *
 * Created on April 10, 2007, 9:14 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package org.atomojo.app.db;

import java.net.URI;

/**
 *
 * @author alex
 */
public class Term extends DBObject
{
   int id;
   URI uri;
   String term;
   String scheme;
   
   /** Creates a new instance of Term */
   public Term(DB db,int id,URI uri)
   {
      super(db);
      this.id = id;
      this.uri = uri;
   }
   
   public static void split(URI uri,String [] parts)
   {
      String path = uri.getPath();
      String [] segments = path.split("/");
      String term = segments[segments.length-1];
      String scheme = uri.toString();
      scheme = scheme.substring(0,scheme.length()-term.length());
      parts[0] = scheme;
      parts[1] = term;
   }
   
   protected void init() {
      synchronized (this) {
         String path = uri.getPath();
         String [] segments = path.split("/");
         term = segments[segments.length-1];
         scheme = uri.toString();
         scheme = scheme.substring(0,scheme.length()-term.length());
      }
   }
   
   public int getId() {
      return id;
   }
   
   public URI getURI() {
      return uri;
   }
   
   public String getName() {
      if (term==null) {
         init();
      }
      return term;
   }
   
   public String getScheme() {
      if (scheme==null) {
         init();
      }
      return scheme;
   }
   
}
